package com.lk.device.service.impl;

import com.lk.base.mysql.domain.TblSysset;
import com.lk.base.mysql.repository.TblSyssetRepository;
import com.lk.device.service.SyssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class SyssetServiceImpl implements SyssetService {

    @Autowired
    private TblSyssetRepository tblSyssetRepository;

    @Override
    public List<TblSysset> selectAll() {
        List<TblSysset> all = tblSyssetRepository.findAll();
        return all;
    }

    @Override
    public TblSysset save(TblSysset dto) {
        Optional<TblSysset> byId = tblSyssetRepository.findById(dto.getId());
        TblSysset tblSysset = byId.get();
        tblSysset.setGzq(dto.getGzq());
        tblSysset.setJjq(dto.getJjq());
        tblSysset.setJzq(dto.getJzq());
        tblSyssetRepository.save(tblSysset);
        return tblSysset;
    }
}
